﻿using System;
using System.Collections.Generic;

namespace Communergy.Common.Comparers
{
    public class EnergyDataComparer : IEqualityComparer<EnergyData>
    {

        #region IEqualityComparer<EnergyData> Members

        public bool Equals(EnergyData x, EnergyData y)
        {
            bool isEqual = DateTimeAndIntervalAreEqual(x, y);
            return isEqual;
        }

        public int GetHashCode(EnergyData energyData)
        {
            var hash = energyData.ReadingDateTime.Ticks * energyData.Interval.Ticks ;
            return hash.GetHashCode();
        }

        #endregion
        private static bool DateTimeAndIntervalAreEqual(EnergyData x, EnergyData y)
        {
            return (x.ReadingDateTime == y.ReadingDateTime && x.Interval == y.Interval);
        }
    }
}
